import request from "@/utils/request";
//引入接口类型
import type {
  ResponesSpu,
  resAllTradeMarkList,
  SpuImageList,
  ResponseData,
  AttrResponse,
  SkuDate,
  SkuInfo,
} from "./type";
enum API {
  //获取已有属性
  GETSPU_URL = "/admin/product/",
  //获取所有spu品牌属性
  ALLTRADEMARK_URL = "/admin/product/baseTrademark/getTrademarkList",
  //获取对呀品牌的图片
  GETSPUIMAGE_URL = "/admin/product/spuImageList/",
  //获取某一个品牌下对应的品牌属性
  GETSPUATTR_URL = "/admin/product/spuSaleAttrList/",
  //获取整个项目的品牌属性
  GETALLPRODUCT_URL = "/admin/product/baseSaleAttrList",
  //修改spu接口
  UPDATESPU_URL = "/admin/product/updateSpuInfo",
  //添加spu
  ADDSPU_URL = "/admin/product/saveSpuInfo",
  //添加sku
  ADDSKU_URL = "/admin/product/saveSkuInfo",
  //获取sku详细接口
  GETSKUINFO_URL = "/admin/product/findBySpuId/",
  //删除spu接口
  DELETESPU_URL = "/admin/product/deleteSpu/",
}
//获取spu信息
export const getSpuList = (
  page: any,
  limit: any,
  category3Id: number | string,
) =>
  request.get<any, ResponesSpu>(
    API.GETSPU_URL + `${page}/${limit}?category3Id=${category3Id}`,
  );
//获取所有品牌
export const getAllTrademark = () =>
  request.get<any, resAllTradeMarkList>(API.ALLTRADEMARK_URL);
//获取对应品牌的图片
export const getSpuImageList = (spuId: number) =>
  request.get<any, SpuImageList>(API.GETSPUIMAGE_URL + spuId);
//获取某一个品牌下对应的品牌属性
export const getSpuAttrList = (spuId: number) =>
  request.get<any, ResponseData>(API.GETSPUATTR_URL + spuId);
//获取整个项目的品牌属性
export const getAllProduct = () =>
  request.get<any, AttrResponse>(API.GETALLPRODUCT_URL);
//添加或修改spu接口
export const addOrUpdateSpu = (data: any) => {
  console.log(data.id);

  if (data.id) {
    return request.post(API.UPDATESPU_URL, data);
  } else {
    return request.post(API.ADDSPU_URL, data);
  }
};
//添加sku属性
export const reqAddSku = (data: SkuDate) =>
  request.post<any, any>(API.ADDSKU_URL, data);

//获取sku详细接口
export const reqGetSkuInfo = (skuId: number) =>
  request.get<any, SkuInfo>(API.GETSKUINFO_URL + skuId);

//删除spu接口
export const reqDeleteSpu = (spuId: number) =>
  request.delete<any, any>(API.DELETESPU_URL + spuId);
